
#!coding:utf-8
# vim: tabstop=4 shiftwidth=4 softtabstop=4
"""
    @author jay.han
"""
from cvirt.cnode.storage.libvirtStorage import TcloudStoragePool
from cvirt.common.constant import StorageStatus
from cvirt.cnode.test import fakeLibvirt
from cvirt.common.test import BaseTest
from cvirt.manager.models import Cluster,Storage
from cvirt.cnode.storage.api import API as api



class TestStorageDriver(BaseTest):

    def setUp(self):
        super(TestStorageDriver, self).setUp()

        self.host = "127.0.0.1"
        self._conn = fakeLibvirt.open("test:\\test")

        self.service = api

        def buildStorage():
            cluster = Cluster.objects.all()[:1]
            if not cluster:
                cluster = Cluster()
                cluster.update({'name':'123',
                                "description":'abc',
                                "cpufamily":"AMD"})
                cluster.save()
                return cluster
            else:
                return cluster[0]

        self.cluster = buildStorage()


    def tearDown(self):
        try:
            Storage.objects.all().delete()
            api.delete_pool('test-nfs')
            api.delete_pool('test-local')
        except:
            pass
        super(TestStorageDriver, self).tearDown()

    #TEST LOCAL
    def testLocalPool(self):



        self.storage = {
            'name':'test-local',
            'host':'127.0.0.1',
            'username':'jay',
            'password':"123456",
            'cluster':self.cluster.id,
            'source_path':'test'
        }
        rt = self.service.create_pool(_type=TcloudStoragePool.LOCAL,storage=self.storage)

        self.assertEqual(rt,True)


    def testNetfsPool(self):
        self.storage = {
            'name':'test-nfs',
            'host':'172.16.10.245',
            'username':'jay',
            'password':"123456",
            'cluster':self.cluster.id,
            'source_path':'/home/vmos/instances'
        }
        rt = self.service.create_pool(_type=TcloudStoragePool.NETFS,storage=self.storage)

        self.assertEqual(rt,True)